package com.chamberlain.web.controller.equipment;

import com.chamberlain.equipment.domain.Electric;
import com.chamberlain.equipment.service.IElectricService;
import com.chamberlain.common.annotation.Log;
import com.chamberlain.common.core.controller.BaseController;
import com.chamberlain.common.core.domain.AjaxResult;
import com.chamberlain.common.core.page.TableDataInfo;
import com.chamberlain.common.enums.BusinessType;
import com.chamberlain.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author: CYY
 * @date: 2024/3/25
 */
@RestController
@RequestMapping("/equipment/electric")
public class ElectricController extends BaseController {
    @Autowired
    private IElectricService electricService;

    /**
     * 查询电能设备列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:electric:list')")
    @GetMapping("/list")
    public TableDataInfo list(Electric electric)
    {
        startPage();
        List<Electric> list = electricService.selectElectricList(electric);
        return getDataTable(list);
    }

    /**
     * 导出电能设备列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:electric:export')")
    @Log(title = "电能设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Electric electric)
    {
        List<Electric> list = electricService.selectElectricList(electric);
        ExcelUtil<Electric> util = new ExcelUtil<Electric>(Electric.class);
        util.exportExcel(response, list, "电能设备数据");
    }

    /**
     * 获取电能设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:electric:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(electricService.selectElectricById(id));
    }

    /**
     * 新增电能设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:electric:add')")
    @Log(title = "电能设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Electric electric)
    {
        return toAjax(electricService.insertElectric(electric));
    }

    /**
     * 修改电能设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:electric:edit')")
    @Log(title = "电能设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Electric electric)
    {
        return toAjax(electricService.updateElectric(electric));
    }

    /**
     * 删除电能设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:electric:remove')")
    @Log(title = "电能设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(electricService.deleteElectricByIds(ids));
    }
}
